﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Office.ActiveX;
using System.Diagnostics;

namespace OPENXMLLib
{
    public class ActiveXResolver
    {
        public static void Resolve(SpreadsheetDocument xDoc)
        {
            //Sheet sheet = xDoc.WorkbookPart.Workbook.GetFirstChild<Sheets>().Elements<Sheet>().Where(p => p.Name == "00-Control").SingleOrDefault();

            //if (sheet == null)
            //{
            //    return string.Empty;
            //}

            //WorksheetPart worksheetPart = (WorksheetPart)xDoc.WorkbookPart.GetPartById(sheet.Id);
            //ActiveXControlData activeX = xDoc.WorkbookPart.
            //xDoc.WorkbookPart.GetPartsOfType<ActiveXPart>

            //var list = xDoc.GetPartsOfType<ActiveXControlData>().ToList();

            //foreach (IdPartPair item in xDoc.Parts)
            //{

            //    Debug.WriteLine(item.OpenXmlPart.Uri);
            //    Dump(item.OpenXmlPart);
            //}

            //foreach (WorksheetPart wsp in xDoc.WorkbookPart.WorksheetParts)
            //{

            //    foreach (DocumentFormat.OpenXml.Spreadsheet.Control ctrl in wsp.Worksheet.Descendants<DocumentFormat.OpenXml.Spreadsheet.Control>())
            //    {
            //        ctrl.Remove();
            //    }
            //}
        }

        private static void Dump(OpenXmlPart part)
        {
            foreach (var item in part.Parts)
            {
                Debug.WriteLine(item.OpenXmlPart.Uri);
            }
        }
    }
}
